<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>09.vue动态组件</title>
</head>
<body>
    <div id="app">
        <component :is="type"></component>
        <child-one v-if="type === 'child-one'">
        </child-one>
        <child-two v-if="type === 'child-two'"></child-two>
        <button @click="handleBtnClick">change</button>
    </div>
</body>
<script src="vue.js"></script>
<script>
    Vue.component('child-one', {
        template: `<div v-once>child-one</div>`
    })
    Vue.component('child-two', {
        template: '<div v-once>child-two</div>'
    })
    var app = new Vue({
        el: '#app',
        data: {
            type: 'child-one'
        },
        methods: {
            handleBtnClick() {
                this.type = this.type === 'child-one'? 'child-two':'child-one';
            }
        }
    })
</script>
</html>